package com.xiaomi.front.service.shopp_cart;

import com.xiaomi.front.dao.Shopping_cart.ShoppCartDao;
import com.xiaomi.pojo.Shoppingcart;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ShoppCartServiceImpl implements ShoppCartService {


    @Autowired
    private ShoppCartDao shoppCartDao;

    /*
    根据用户id/商品详情编号 查询购物车是否有该商品
    有：修改购物车
    无：添加购物车表
     */
    @Override
    public int ExitsCart(int userid, int commid) {
        Shoppingcart shoppingcart = shoppCartDao.ExistComm(userid, commid);
        if (shoppingcart == null) {
            int count = shoppCartDao.AddShopp_cart(userid, commid);
            return count;
        } else {
            int count = shoppCartDao.UpdateShopp_cart(userid, commid);
            return count;
        }
    }

    //加购物车后/查看商品名称/配置
    @Override
    public Shoppingcart getCart(int userid, int deid) {
        return shoppCartDao.getCart(userid, deid);
    }

    //根据用户id/商品详情id 存购物车
    @Override
    public int AddShopp_cart(int userid, int commid) {
        return shoppCartDao.AddShopp_cart(userid, commid);
    }

    //修改购物车
    //加购物车
    @Override
    public int UpdateShopp_cart(int userid, int commid) {
        return shoppCartDao.UpdateShopp_cart(userid, commid);
    }

    //减购物车
    @Override
    public int reduceCart(int userid, int commid) {
        return shoppCartDao.reduceCart(userid, commid);
    }

    //删除购物车
    @Override
    public int DeleteShopp_cart(int[] deid, int userid) {
        return shoppCartDao.DeleteShopp_cart(deid, userid);
    }

    //根据uid查看购物车详情
    @Override
    public List<Shoppingcart> getShoppCart(int id) {
        return shoppCartDao.getShoppCart(id);
    }

    //根据id查购物车数量
    @Override
    public int CartCount(int uid) {
        return shoppCartDao.CartCount(uid);
    }

    //根据购物车编号查购物车详情
    @Override
    public List<Shoppingcart> getCarts(int[] scid) {
        return shoppCartDao.getCarts(scid);
    }

}
